#define _CRT_SECURE_NO_WARNINGS 1
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

typedef struct ListNode 
{															   
	int val;
	struct ListNode* next;
}ListNode;

struct ListNode* removeElements(ListNode* pHead, int x)
{
	assert(pHead);
	ListNode* tmp = pHead;
	ListNode* bigerNumList, * smallerNumList, * guard1, * guard2;
	guard1 = (ListNode*)malloc(sizeof(ListNode));
	guard2 = (ListNode*)malloc(sizeof(ListNode));

	bigerNumList = guard1;
	smallerNumList = guard2;
	while (tmp)
	{
		if (tmp->val < x)
		{
			smallerNumList->next = tmp;
			smallerNumList = smallerNumList->next;
		}
		else
		{
			bigerNumList->next = tmp;
			bigerNumList = bigerNumList->next;
		}
		tmp = tmp->next;
	}
	smallerNumList->next = guard1->next;
	bigerNumList->next = NULL;
	pHead = guard2->next;
	free(guard1);
	free(guard2);
	return pHead;
}
void test()
{
	ListNode* plist = { 0 };

	ListNode* n1 = (ListNode*)calloc(1, sizeof(ListNode));
	ListNode* n2 = (ListNode*)calloc(1, sizeof(ListNode));
	ListNode* n3 = (ListNode*)calloc(1, sizeof(ListNode));
	ListNode* n4 = (ListNode*)calloc(1, sizeof(ListNode));
	ListNode* n5 = (ListNode*)calloc(1, sizeof(ListNode));
	ListNode* n6 = (ListNode*)calloc(1, sizeof(ListNode));
	ListNode* n7 = (ListNode*)calloc(1, sizeof(ListNode));
	
	n1->next = n2;
	n2->next = n3;
	n3->next = n4;
	n4->next = n5;
	n5->next = n6;
	n6->next = n7;
	n7->next = NULL;

	n1->val = 1;
	n2->val = 8;
	n3->val = 3;
	n4->val = 4;
	n5->val = 5;
	n6->val = 2;
	n7->val = 7;

	removeElements(n1, 4);
}
int main()
{
	test();
	return 0;
}